package demo;

import utils.DBUtils;

import java.sql.*;

/**
 * @author tongchen
 * @create 2022-12-27 13:42
 */
public class selectAll {
    //定义默认的一些把变量
    private static Connection connection;
    private static ResultSet resultSet;
    private static PreparedStatement statement;

    public static void main(String[] args) {

        //获取连接
        try {
            connection = DBUtils.getConnection();
            //定义sql
            String sql="select *from student  ";
            //创建执行器
         statement =connection.prepareStatement(sql);
         //替换变量
        // statement.setString(1,"'' or 1=1");
         //执行语句
           resultSet = statement.executeQuery();
           //获取结果
            while(resultSet.next()){
                int id=resultSet.getInt(1);
                String sn=resultSet.getString(2);
                String name=resultSet.getString(3);
                String qq_email=resultSet.getString(4);
                int classes_id=resultSet.getInt(5);
                System.out.println(id+","+sn+","+name+","+qq_email+","+classes_id);
            }
            //释放资源
            DBUtils.closeResources(connection,statement,resultSet);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
